package org.ourgrid.common.executor.config;

import java.io.File;

import org.ourgrid.common.executor.config.VMWareExecutorConfiguration.PROPERTIES;
import org.ourgrid.common.util.OS;
import org.ourgrid.worker.WorkerConstants;

public class VBoxExecutorConfiguration extends AbstractExecutorConfiguration {

//	public static final String PROPERTY_START_VBOX_COMMAND = "vbox_startcmd";
//	public static final String PROPERTY_START_VBOX_COMMAND = "vbox_stopcmd";
////	public static final String PROPERTY_WAIT_FOR_VBOX_COMMAND = "vbox_waitforcmd";
//	public static final String PROPERTY_START_VBOX_COMMAND = WorkerConstants.PREFIX + "vbox_machinename";
//	public static final String PROPERTY_VBOX_LOCATION = WorkerConstants.PREFIX + "vbox_location";
////	public static final String APP_STD_OUTPUT_FILE_NAME;
	
	
	public static enum PROPERTIES{
		PROPERTY_START_VBOX_COMMAND, PROPERTY_STOP_VBOX_COMMAND, 
		PROPERTY_VBOX_MACHINE_NAME, PROPERTY_SHARED_FOLDER,
		PROPERTY_VBOX_LOCATION, APP_STD_OUTPUT_FILE_NAME, 
		APP_STD_ERROR_FILE_NAME, APP_STD_EXITVALUE_FILE_NAME,
		APP_STD_TERMINATED_FILE_NAME, APP_STD_EXECUTION_SCRIPT_FILE_NAME;
	}
	
	/**
	 * @param rootDir
	 * @param propNames
	 */
	public VBoxExecutorConfiguration(File rootDir, String[] propNames) {
		super(rootDir, propNames);
	}

	public VBoxExecutorConfiguration(File rootDir) {
		super(rootDir, parseProperties());
	}
	
	private static String[] parseProperties(){
		
		String[] properties = new String[PROPERTIES.values().length] ;
		
		for (int i = 0; i < PROPERTIES.values().length; i++) {
			properties[i] = WorkerConstants.PREFIX + PROPERTIES.values()[i].toString();
		}
		
		return properties;
	}
	
	@Override
	public void setDefaultProperties() {
		String startvmCmd = "";
		String stopvmCmd = "";
		
		String path = "\"" +  getRootDir().getAbsolutePath() + File.separator + "deployer" + File.separator + 
						"worker" + File.separator + "sandbox_scripts" + File.separator + 
						"vbox_scripts" + File.separator + "host";
		
		startvmCmd = path + File.separator + "win" + File.separator + "init_vboxenv.bat" + "\"";
		stopvmCmd = path + File.separator + "win" + File.separator + "kill_vboxenv.bat" + "\"";
		
		this.properties.put(PROPERTIES.PROPERTY_START_VBOX_COMMAND.toString(), startvmCmd);
		this.properties.put(PROPERTIES.PROPERTY_STOP_VBOX_COMMAND.toString(), stopvmCmd);
		
		this.properties.put(PROPERTIES.APP_STD_OUTPUT_FILE_NAME.toString(), "app.stdout");
		this.properties.put(PROPERTIES.APP_STD_ERROR_FILE_NAME.toString(), "app.stderr");
		this.properties.put(PROPERTIES.APP_STD_EXITVALUE_FILE_NAME.toString(), "app.exit");
		this.properties.put(PROPERTIES.APP_STD_TERMINATED_FILE_NAME.toString(), ".terminated");
		this.properties.put(PROPERTIES.APP_STD_EXECUTION_SCRIPT_FILE_NAME.toString(), "app.script.sh");
		
	}

}
